Repository navigation
[rexm] Improve .log file saving for test command. - #6111
MatthewRoush wants to merge 4 commits into
Conversation
Need to use `cmd` shell for `del`.
When using a port that's already in use, the server fails to start. Using a different (hopefully less common) port should help mitigate this.
Before, the `test` command used javascript (client) to save the generated log file, which doesn't allow you to specify a path to save the file (for security reasons.) `test` was already using a python server to run the web example, which we can take advantage of. Using a python script (`rexm_web_test_server.py`) we can control how we handle POST requests. With that, we can use javascript to send a POST request to the server, and the server can then save the log file (avoiding client restrictions.) As an added bonus, we don't need `FileSaver.js` anymore.
Forgot to update this.
| // 'Ask where to save each file before downloading' - which you can set true/false. | ||
| // If you enable this setting it would always ask you and bring the SaveAsDialog | ||
| saveAs(blob, localFSname); | ||
| var xhr = new XMLHttpRequest(); |
There was a problem hiding this comment.
Does it require the Python script?
|
@MatthewRoush I don't like |
|
Yes, because we have to implement our own The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a The It is unfortunate to have the extra Python script, but it solves the "how do we save the '.log' file to the specific path that we want in an automated way without requiring the user to just do it themselves" problem that we have. |
|
@MatthewRoush thanks for the detailed explanation but still I prefer let the user manage it manually than adding a Python script dependency. EDIT: Not sure if some of the parts of this PR could also be implemented without the script addition. |
|
Yeah, the two small changes (fixing the Makefile and changing the port number) are unrelated to the script, everything else relies on the script. |
See raysan5#6111 for more details. The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory. The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know. The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL. Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
See raysan5#6111 for more details. The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory. The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know. The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL. Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
See raysan5#6111 for more details. The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory. The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know. The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL. Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
See raysan5#6111 for more details. The primary annoyance with the previous implementation was that it couldn't save a file to a specific path because of browser security restrictions. This means that the file is automatically (or not, if the user has the setting on that makes it prompt every time) saved to the "default" save location, which may not be the traditional "Downloads" directory. The way to bypass the client-side file saving restrictions is to not save the file from the client, but instead from the server (which is also just the client computer, because it's a `localhost://`.) The problem is that the default server from running `python http.server` (which is what we previously did to run the web exmaples) doesn't handle `POST` requests. That means we have to write our own Python script to implement `POST` request handling. We also have to handle `GET` requests since we're using our own request handling logic, as far as I know. The `XMLHttpRequest()` sends the `POST` request from the client to the server, and the Python script (our server) handles that `POST` request. We can send a `POST` request containing the `.log` data, with the URL being the path (relative to the server root) we want to save the `.log` file to (`exBasePath/exCategory/logs/exName.log`). Then, on the server, we can handle that `POST` request by saving the `.log` data we received to the file path specified in the URL. Saving the `.log` file to specific, known location, is especially helpful for `rexm textlog`, which needs to be able to find the `.log` file.
Before, the
testcommand used javascript (client) to save the generated log file, which doesn't allow you to specify a path to save the file to (for security reasons.)testwas already using a python server to run the web example, which we can take advantage of. Using a python script (rexm_web_test_server.py) we can control how we handle POST requests. With that, we can use javascript to send a POST request to the server, and the server can then save the log file (avoiding client restrictions.)As an added bonus, we don't need
FileSaver.jsanymore.Miscellaneous changes
tools/rexm/Makefileso that it usesSHELL=cmdon Windows.testcommand server port number from8080to38080to reduce conflicts with other programs.